package org.springblade.modules.library.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.common.enums.feedback.FeedbackType;
import org.springblade.common.enums.item.ItemOperateType;
import org.springblade.common.enums.library.QuestionType;
import org.springblade.core.tool.api.R;
import org.springblade.modules.library.vo.BaseResourceVo;
import org.springblade.modules.resource.enums.AttachType;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDictBizService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础资源控制器
 * 一些固定的业务枚举等
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-baseResource")
@Api(value = "基础资源控制器", tags = "基础资源接口")
public class BaseResourceController {


	private final IDictBizService dictService;

	/**
	 * 附件业务类型
	 */
	@GetMapping("/attachType")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "附件业务类型", notes = "附件业务类型")
	public R<List<BaseResourceVo>> attachTypelist() {
		List<BaseResourceVo> resultList=new ArrayList<>();
		for (AttachType attachType:AttachType.values()){
			if(AttachType.DEFAULT.equals(attachType)) {
				continue;
			}
			BaseResourceVo vo=new BaseResourceVo();
			vo.setLabel(attachType.getName());
			vo.setValue(attachType.getCategory().toString());
			resultList.add(vo);
		}
		return R.data(resultList);
	}

	/**
	 * 教具操作业务类型
	 */
	@GetMapping("/item-operate-type")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "教具操作业务类型", notes = "教具操作业务类型")
	public R<List<BaseResourceVo>> itemOperateType() {
		List<BaseResourceVo> resultList=new ArrayList<>();
		for (ItemOperateType operateType:ItemOperateType.values()){
			BaseResourceVo vo=new BaseResourceVo();
			vo.setLabel(operateType.getValue());
			vo.setValue(operateType.getCode().toString());
			resultList.add(vo);
		}
		return R.data(resultList);
	}


	/**
	 * 题库管理
	 * 题目类型(单选、多选、判断、简答、客观)
	 */
	@GetMapping("/bank-question-type")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "题库-题目类型", notes = "题目类型")
	public R<List<BaseResourceVo>> questionType() {
		List<BaseResourceVo> resultList=new ArrayList<>();
		for (QuestionType questionType: QuestionType.values()){
			if (QuestionType.SHORT.equals(questionType))continue; //业务不需要填空题
			BaseResourceVo vo=new BaseResourceVo();
			vo.setLabel(questionType.getValue());
			vo.setValue(questionType.getCode().toString());
			resultList.add(vo);
		}
		return R.data(resultList);
	}


	/**
	 * 根据字典编号查询对应的子项
	 */
	@GetMapping("/feedbackType")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "反馈类型", notes = "反馈类型")
	public R<List<BaseResourceVo>> feedback() {
		List<BaseResourceVo> resultList=new ArrayList<>();
		for (FeedbackType type: FeedbackType.values()){
			BaseResourceVo vo=new BaseResourceVo();
			vo.setLabel(type.getValue());
			vo.setValue(type.getCode().toString());
			resultList.add(vo);
		}
		return R.data(resultList);
	}



	/**
	 * 根据字典编号查询对应的子项
	 */
	@GetMapping("/code")
	@ApiOperationSupport(order = 10)
	@ApiOperation(value = "业务字典", notes = "从业务字典拿分类")
	public R<List<BaseResourceVo>> code(String code) {
		List<DictBiz> treeList = dictService.getList(code);
		List<BaseResourceVo> resultList=new ArrayList<>();
		for (DictBiz dictBiz: treeList){
			BaseResourceVo vo=new BaseResourceVo();
			vo.setLabel(dictBiz.getDictValue());
			vo.setValue(dictBiz.getDictKey());
			resultList.add(vo);
		}
		return R.data(resultList);
	}


}
